//
//  ERRunningVC.m
//  EnjoyRunning
//
//  Created by ljm on 2017/3/15.
//  Copyright © 2017年 ljm. All rights reserved.
//

#import "ERRunningVC.h"
#import "ERBoard.h"

#import "ERWalkVC.h"
#import "ERRunVC.h"
#import "ERCyclingVC.h"

@interface ERRunningVC ()

@end

@implementation ERRunningVC

#pragma mark -- 设置navigation导航条
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.navigationController.navigationBar setBarTintColor:[UIColor whiteColor]];
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor blackColor]}];
    
    
    UIButton *leftBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 30, 30)];
    [leftBtn setImage:[UIImage imageNamed:@"mine_normal"] forState:UIControlStateNormal];
    UIBarButtonItem *selfLeftImage = [[UIBarButtonItem alloc]initWithCustomView:leftBtn];
    self.navigationItem.leftBarButtonItem = selfLeftImage;
    
    //right
    UIButton *rightBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 30, 30)];
    [rightBtn setImage:[UIImage imageNamed:@"mine_select"] forState:UIControlStateNormal];
    [rightBtn setTintColor:[UIColor whiteColor]];
    UIBarButtonItem *selfRightImage = [[UIBarButtonItem alloc]initWithCustomView:rightBtn];
    self.navigationItem.rightBarButtonItem = selfRightImage;
    
    self.navigationController.navigationBar.hidden = NO;
    self.tabBarController.tabBar.hidden = NO;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setupUI];
}

#pragma mark -- setup interface
- (void)setupUI
{
    /*
     *    画圆
     */
    ERBoard *circular = [[ERBoard alloc] initWithFrame:[UIScreen mainScreen].bounds];
    
    circular.backgroundColor = self.view.backgroundColor;
    
    [self.view addSubview:circular];
    
    /*
     *    地点
     */
    UILabel *locationLab = [[UILabel alloc] initWithFrame:CGRectMake(10, 70, 100, 44)];
    [locationLab setText:@"云南 昆明"];
    locationLab.backgroundColor = [UIColor clearColor];
//    locationLab.font = [UIFont fontWithName:@"JMiMi" size:30*AAdaptionWidth()];
    locationLab.font = AAFont(25);
    [locationLab setTextColor:[UIColor grayColor]];
    locationLab.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:locationLab];
    
    /*
     *    空气质量
     */
    UILabel *airQualitrLab = [[UILabel alloc]initWithFrame:CGRectMake(kwidth - locationLab.frame.size.width - 10, locationLab.frame.origin.y, locationLab.frame.size.width - 30, locationLab.frame.size.height)];
//    airQualitrLab.backgroundColor = [UIColor greenColor];
    airQualitrLab.backgroundColor = locationLab.backgroundColor;
    airQualitrLab.text = @"空气质量:";
    airQualitrLab.font = locationLab.font;
    airQualitrLab.textColor = locationLab.textColor;
    airQualitrLab.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:airQualitrLab];
    
    /*
     *    空气等级：优良中差
     */
    UILabel *airRequestLab = [[UILabel alloc]initWithFrame:CGRectMake(airQualitrLab.frame.origin.x + airQualitrLab.frame.size.width, airQualitrLab.frame.origin.y, 30, airQualitrLab.frame.size.height)];
    airRequestLab.backgroundColor = locationLab.backgroundColor;
    airRequestLab.text = @"优";
    airRequestLab.font = locationLab.font;
    airRequestLab.textColor = locationLab.textColor;
    airRequestLab.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:airRequestLab];
    
    /*
     *    总里程
     */
    UILabel *totalDistanceLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 80, 44)];
    totalDistanceLab.center = CGPointMake(kwidth/2, locationLab.frame.origin.y + locationLab.frame.size.height + totalDistanceLab.frame.size.height);
    totalDistanceLab.text = @"总里程";
    totalDistanceLab.backgroundColor = locationLab.backgroundColor;
    totalDistanceLab.font = locationLab.font;
    totalDistanceLab.textColor = locationLab.textColor;
    totalDistanceLab.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:totalDistanceLab];
    
    /*
     *    里程数
     */
    UILabel *totalMileageLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, kwidth * 0.5, 44)];
    totalMileageLab.center = CGPointMake(kwidth/2, totalDistanceLab.frame.origin.y + totalDistanceLab.frame.size.height + 25);
    totalMileageLab.backgroundColor = locationLab.backgroundColor;
    totalMileageLab.text = @"1138.8KM";
    totalMileageLab.textColor = [UIColor whiteColor];
    totalMileageLab.textAlignment = NSTextAlignmentCenter;
    totalMileageLab.font = AAFont(55);
    [self.view addSubview:totalMileageLab];
    
    
    /*
     *    累计用时
     */
    UILabel *allTimeLab = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 90, 30)];
    allTimeLab.center = CGPointMake(kwidth * 0.25, kheight * 0.54);
    allTimeLab.backgroundColor = locationLab.backgroundColor;
    allTimeLab.text = @"累计用时";
    allTimeLab.textColor = [UIColor grayColor];
    allTimeLab.textAlignment = NSTextAlignmentCenter;
    allTimeLab.font = locationLab.font;
    [self.view addSubview:allTimeLab];
    
    /*
     *    所用时间
     */
    UIButton *allTimeBtn = [[UIButton alloc]initWithFrame:CGRectMake(allTimeLab.frame.origin.x, allTimeLab.frame.origin.y + allTimeLab.frame.size.height, allTimeLab.frame.size.width, allTimeLab.frame.size.height)];
//    allTimeBtn.backgroundColor = [UIColor redColor];
    allTimeBtn.backgroundColor = [UIColor clearColor];
    [allTimeBtn setTitle:@"8小时" forState:UIControlStateNormal];
    [allTimeBtn setTitleColor:[UIColor whiteColor]];
//    [allTimeBtn setTitleFont:FontNameAlNileBold size:20];
    [self.view addSubview:allTimeBtn];
    
    /*
     *    跑步记录
     */
    UILabel *runRecordLab = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, allTimeLab.frame.size.width, allTimeLab.frame.size.height)];
    runRecordLab.center = CGPointMake(kwidth * 0.75, allTimeLab.center.y);
    runRecordLab.backgroundColor = allTimeLab.backgroundColor;
    runRecordLab.text = @"跑步记录";
    runRecordLab.textColor = allTimeLab.textColor;
    runRecordLab.textAlignment = NSTextAlignmentCenter;
    runRecordLab.font = allTimeLab.font;
    [self.view addSubview:runRecordLab];
    
    /*
     *    跑步记录时间
     */
    UIButton *runRecordBtn = [[UIButton alloc]initWithFrame:CGRectMake(runRecordLab.frame.origin.x, runRecordLab.frame.origin.y + runRecordLab.frame.size.height, runRecordLab.frame.size.width, runRecordLab.frame.size.height)];
    runRecordBtn.backgroundColor = allTimeBtn.backgroundColor;
    [runRecordBtn setTitle:@"8小时" forState:UIControlStateNormal];
    [runRecordBtn setTitleColor:allTimeBtn.currentTitleColor];
    [self.view addSubview:runRecordBtn];
    
    /*
     *    跑步日历
     */
    UILabel *runCalenderLab = [[UILabel alloc]initWithFrame:CGRectMake(allTimeBtn.frame.origin.x, allTimeBtn.frame.origin.y + allTimeBtn.frame.size.height + kheight * 0.02, allTimeLab.frame.size.width, allTimeLab.frame.size.height)];
    runCalenderLab.backgroundColor = allTimeLab.backgroundColor;
    runCalenderLab.text = @"跑步日历";
    runCalenderLab.textColor = allTimeLab.textColor;
    runCalenderLab.textAlignment = NSTextAlignmentCenter;
    runCalenderLab.font = allTimeLab.font;
    [self.view addSubview:runCalenderLab];
    
    /*
     *    跑步日历按钮
     */
    UIButton *runCalenderBtn = [[UIButton alloc]initWithFrame:CGRectMake(runCalenderLab.frame.origin.x, runCalenderLab.frame.origin.y + runCalenderLab.frame.size.height, runCalenderLab.frame.size.width, runCalenderLab.frame.size.height)];
    runCalenderBtn.backgroundColor = allTimeBtn.backgroundColor;
    [runCalenderBtn setTitle:@"日历" forState:UIControlStateNormal];
    [runCalenderBtn setTitleColor:allTimeBtn.currentTitleColor];
    [self.view addSubview:runCalenderBtn];
    
    /*
     *    最佳记录
     */
    UILabel *bestRecordLab = [[UILabel alloc]initWithFrame:CGRectMake(runRecordBtn.frame.origin.x, runRecordBtn.frame.origin.y + runRecordBtn.frame.size.height + kheight * 0.02, runRecordBtn.frame.size.width, runRecordBtn.frame.size.height)];
    bestRecordLab.backgroundColor = allTimeLab.backgroundColor;
    bestRecordLab.text = @"最佳记录";
    bestRecordLab.textColor = allTimeLab.textColor;
    bestRecordLab.textAlignment = NSTextAlignmentCenter;
    bestRecordLab.font = allTimeLab.font;
    [self.view addSubview:bestRecordLab];
    
    /*
     *    最佳记录用时
     */
    UIButton *bestRecordBtn = [[UIButton alloc]initWithFrame:CGRectMake(bestRecordLab.frame.origin.x, bestRecordLab.frame.origin.y + bestRecordLab.frame.size.height, bestRecordLab.frame.size.width, bestRecordLab.frame.size.height)];
    bestRecordBtn.backgroundColor = allTimeBtn.backgroundColor;
    [bestRecordBtn setTitle:@"8小时" forState:UIControlStateNormal];
    [bestRecordBtn setTitleColor:allTimeBtn.currentTitleColor];
    [self.view addSubview:bestRecordBtn];
    
    
    /*
     *    开始运动
     */
    UIButton *startPlayBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, kwidth * 0.2, kwidth * 0.2)];
    startPlayBtn.center = CGPointMake(kwidth * 0.5, kheight * 0.8);
    startPlayBtn.backgroundColor = [UIColor whiteColor];
    startPlayBtn.layer.cornerRadius = kwidth * 0.1;
    startPlayBtn.layer.masksToBounds = YES;
    
    startPlayBtn.layer.borderWidth = 1.f;
    startPlayBtn.layer.borderColor = [UIColor colorWithHex:0xff6d02 alpha:1.f].CGColor;
    [startPlayBtn setImage:[UIImage imageNamed:@"exercise_select"] forState:UIControlStateNormal];
    [self.view addSubview:startPlayBtn];
    
    
    
    /*
     *    设置tag值
     */
    allTimeBtn.tag = 100;
    runRecordBtn.tag = 101;
    runCalenderBtn.tag = 102;
    bestRecordBtn.tag = 103;
    startPlayBtn.tag = 104;
    
    /*
     *    设置相应的点击事件
     */
    [allTimeBtn addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
    [runRecordBtn addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
    [runCalenderBtn addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
    [bestRecordBtn addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
    [startPlayBtn addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
}
    
#pragma mark -- actions
    - (void)btnClicked:(UIButton *)btn
    {
        switch (btn.tag) {
            case 100:
            {
                /*
                 *    累计用时
                 */
                
            }
            break;
            
            case 101:
            {
                /*
                 *    跑步记录
                 */
                
            }
            break;
            
            case 102:
            {
                /*
                 *    跑步日历
                 */
                
            }
            break;
            
            case 103:
            {
                /*
                 *    最佳记录
                 */
                
            }
            break;
            default:
            {
                /*
                 *    开始运动
                 */
                ERWalkVC *walkVC = [[ERWalkVC alloc] init];
                walkVC.title = @"走路";
                [self.navigationController pushViewController:walkVC animated:YES];
                
            }
            break;
        }
    }
@end
